home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Framework / Sources / UControl.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  66.2 KB  |  2,246 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UControl.cp
  3. // Copyright © 1987-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __UCONTROL__
  7. #include "UControl.h"
  8. #endif
  9.  
  10. // MacApp
  11.  
  12. #ifndef __UADORNERS__
  13. #include "UAdorners.h"
  14. #endif
  15.  
  16. //    #ifndef __UAPPLICATION__
  17. //    #include "UApplication.h"
  18. //    #endif
  19.  
  20. #ifndef __UCOREGLOBALS__
  21. #include "UCoreGlobals.h"
  22. #endif
  23.  
  24. #ifndef __UCOREUTILITIES__
  25. #include "UCoreUtilities.h"
  26. #endif
  27.  
  28. #ifndef __UDRAWINGENVIRONMENT__
  29. #include "UDrawingEnvironment.h"
  30. #endif
  31.  
  32. #ifndef __UDISPATCHER__
  33. #include "UDispatcher.h"
  34. #endif
  35.  
  36. #ifndef __UITERATOR__
  37. #include "UIterator.h"
  38. #endif
  39.  
  40. #ifndef __ULIST__
  41. #include "UList.h"
  42. #endif
  43.  
  44. #ifndef __UMACAPPGLOBALS__
  45. #include "UMacAppGlobals.h"
  46. #endif
  47.  
  48. #ifndef __UMACAPPUTILITIES__
  49. #include "UMacAppUtilities.h"
  50. #endif
  51.  
  52. #ifndef __UMEMORY__
  53. #include "UMemory.h"
  54. #endif
  55.  
  56. #ifndef __USCROLLER__
  57. #include "UScroller.h"
  58. #endif
  59.  
  60. #ifndef __USTREAM__
  61. #include "UStream.h"
  62. #endif
  63.  
  64. #ifndef __UWINDOW__
  65. #include "UWindow.h"
  66. #endif
  67.  
  68. // Toolbox
  69.  
  70. #ifndef __BALLOONS__
  71. #include <Balloons.h>
  72. #endif
  73.  
  74. #ifndef __ERRORS__
  75. #include <Errors.h>
  76. #endif
  77.  
  78. #ifndef __WINDOWS__
  79. #include <Windows.h>
  80. #endif
  81.  
  82. // ANSI
  83.  
  84. #ifndef __LIMITS__
  85. #include <limits.h>
  86. #endif
  87.  
  88. #ifndef __STDIO__
  89. #include <stdio.h>
  90. #endif
  91.  
  92. #ifndef __STDLIB__
  93. #include <stdlib.h>
  94. #endif
  95.  
  96.  
  97. //========================================================================================
  98. // GLOBAL Procedures
  99. //========================================================================================
  100. static pascal void ActionProcForTScrollBar(ControlRef aCMgrControl,
  101.                                            short partCode);
  102.  
  103. //========================================================================================
  104. // CLASS CWhileFocused
  105. //========================================================================================
  106. #undef Inherited
  107.  
  108. //----------------------------------------------------------------------------------------
  109. // CWhileFocused::new: 
  110. //----------------------------------------------------------------------------------------
  111. #pragma segment MAControlRes
  112.  
  113. void* CWhileFocused::operator new(size_t /*size*/)
  114. {
  115.     // prevent heap-based allocation
  116.     return NULL;
  117. }
  118.  
  119. //----------------------------------------------------------------------------------------
  120. // CWhileFocused::delete: 
  121. //----------------------------------------------------------------------------------------
  122. #pragma segment MAControlRes
  123.  
  124. void CWhileFocused::operator delete(void*)
  125. {
  126. }
  127.  
  128. //----------------------------------------------------------------------------------------
  129. // CWhileFocused::CWhileFocused:
  130. //----------------------------------------------------------------------------------------
  131. #pragma segment MAControlRes
  132.  
  133. CWhileFocused::CWhileFocused(TCtlMgr * itsCtlMgr, Boolean redraw) :
  134.     fCtlMgr(itsCtlMgr),
  135.     fRedraw(redraw)
  136. {
  137.     // Setup the FailInfo to catch any failures while this object is in scope
  138.     fFailInfo.SetCleanupProc(CWhileFocused::CallCleanup, this);
  139.  
  140.     fDidFocus = FALSE;
  141.     if (fCtlMgr->fCMgrControl)
  142.     {
  143.         if (fRedraw && fCtlMgr->Focus())
  144.         {
  145.             fDidFocus = TRUE;
  146.  
  147.             CRect qdArea(fCtlMgr->ControlQDArea());
  148.         
  149.             Boolean wasVisible = fCtlMgr->SetCMgrVisibility(FALSE);
  150.             fOldControlLocation = ((CRect&)(*fCtlMgr->fCMgrControl)->contrlRect)[topLeft]; // I'd rather have an accessor!!!
  151.             MoveControl(fCtlMgr->fCMgrControl, qdArea.left, qdArea.top); //SRF
  152.             fCtlMgr->SetCMgrVisibility(wasVisible);
  153.         }
  154.         else
  155.             fWasVisible = fCtlMgr->SetCMgrVisibility(FALSE);
  156.     }
  157. } // CWhileFocused::CWhileFocused
  158.  
  159. //----------------------------------------------------------------------------------------
  160. // CWhileFocused::~CWhileFocused: 
  161. //----------------------------------------------------------------------------------------
  162. #pragma segment MAControlRes
  163.  
  164. CWhileFocused::~CWhileFocused()
  165. {
  166.     this->Cleanup();
  167.  
  168.     fFailInfo.Success();
  169. } // CWhileFocused::~CWhileFocused 
  170.  
  171. //----------------------------------------------------------------------------------------
  172. // CWhileFocused::Cleanup: 
  173. //----------------------------------------------------------------------------------------
  174. #pragma segment MAControlRes
  175.  
  176. void CWhileFocused::Cleanup()
  177. {
  178.     if (fCtlMgr->fCMgrControl)
  179.         if (fDidFocus)
  180.         {
  181.             Boolean wasVisible = fCtlMgr->SetCMgrVisibility(FALSE);
  182.             MoveControl(fCtlMgr->fCMgrControl, fOldControlLocation.h, fOldControlLocation.v); //SRF
  183.             fCtlMgr->SetCMgrVisibility(wasVisible); 
  184.         }
  185.         else
  186.             fCtlMgr->SetCMgrVisibility(fWasVisible);    // …restore visibility 
  187. } // CWhileFocused::Cleanup 
  188.  
  189. //----------------------------------------------------------------------------------------
  190. // CWhileFocused::CallCleanup: 
  191. //----------------------------------------------------------------------------------------
  192. #pragma segment MAControlRes
  193.  
  194. /*static*/ void CWhileFocused::CallCleanup(void* context)
  195. {
  196.     ((CWhileFocused*) context)->Cleanup();
  197. } // CWhileFocused::CallCleanup 
  198.  
  199. //========================================================================================
  200. // GLOBAL Procedures
  201. //========================================================================================
  202. #undef Inherited
  203.  
  204. //----------------------------------------------------------------------------------------
  205. // ActionProcForTScrollBar:
  206. //----------------------------------------------------------------------------------------
  207. #pragma segment MAControlRes
  208.  
  209. pascal void ActionProcForTScrollBar(ControlRef aCMgrControl,
  210.                                     short partCode)
  211. {
  212.     TScrollBar * aScrollBar;
  213.  
  214.     aScrollBar = (TScrollBar *)(GetControlReference(aCMgrControl));
  215.     FailNIL(aScrollBar);                        // What else you gonna' do? 
  216.  
  217.     aScrollBar->ActionProc(partCode);
  218.  
  219. } // ActionProcForTScrollBar
  220.  
  221.  
  222. //========================================================================================
  223. // CLASS TControlTracker
  224. //========================================================================================
  225. #undef Inherited
  226. #define Inherited TTracker
  227.  
  228. #pragma segment MASelCommand
  229. MA_DEFINE_CLASS_M1(TControlTracker, Inherited);
  230.  
  231. //----------------------------------------------------------------------------------------
  232. // TControlTracker constructor
  233. //----------------------------------------------------------------------------------------
  234. #pragma segment MASelCommand
  235.  
  236. TControlTracker::TControlTracker()
  237. {
  238.     fControl = NULL;
  239.     fTrackNonMovement = TRUE;
  240.     fViewConstrain = FALSE;
  241. } // TControlTracker::TControlTracker
  242.  
  243. //----------------------------------------------------------------------------------------
  244. // TControlTracker destructor
  245. //----------------------------------------------------------------------------------------
  246. #pragma segment MADestructorRes
  247.  
  248. TControlTracker::~TControlTracker()
  249. {
  250. }
  251.  
  252. //----------------------------------------------------------------------------------------
  253. // TControlTracker::IControlTracker:
  254. //----------------------------------------------------------------------------------------
  255. #pragma segment MASelCommand
  256.  
  257. void TControlTracker::IControlTracker(TControl* theControl,
  258.                                       const VPoint& itsMouse)
  259. {
  260.     this->ITracker(cTrackingControl, theControl, kCantUndo, kDoesNotCauseChange, NULL,
  261.                     theControl, theControl->GetScroller(kImmediateSuperView), itsMouse);
  262. #if qDebug
  263.     if (theControl == NULL)
  264.         ProgramBreak("Control passed to IControlTracker can''t be NULL.");
  265. #endif
  266.  
  267.     fControl = theControl;
  268. } // TControlTracker::IControlTracker
  269.  
  270.  
  271. //========================================================================================
  272. // CLASS TControl
  273. //========================================================================================
  274. #undef Inherited
  275. #define Inherited TView
  276.  
  277. #pragma segment MAOpen
  278. MA_DEFINE_CLASS_M1(TControl, Inherited);
  279.  
  280. //----------------------------------------------------------------------------------------
  281. // TControl constructor
  282. //----------------------------------------------------------------------------------------
  283. #pragma segment MAOpen
  284.  
  285. TControl::TControl()
  286. {
  287.     fEventNumber = mOKHit;
  288.     fHilite = FALSE;
  289.     fDimmed = FALSE;
  290.     fSizeable = TRUE;
  291.     fInset = gZeroVRect;
  292.     fTextStyle = gSystemStyle;
  293.     fTextStyleRsrcID = kNoResource;
  294.     fPreferOutline = kDontPreferOutline;
  295. } // TControl::TControl
  296.  
  297. //----------------------------------------------------------------------------------------
  298. // TControl destructor
  299. //----------------------------------------------------------------------------------------
  300. #pragma segment MADestructorRes
  301.  
  302. TControl::~TControl()
  303. {
  304. }
  305.  
  306. //----------------------------------------------------------------------------------------
  307. // TControl::IControl:
  308. //----------------------------------------------------------------------------------------
  309. #pragma segment MAOpen
  310.  
  311. void TControl::IControl(TView* itsSuperView,
  312.                         const VPoint& itsLocation,
  313.                         const VPoint& itsSize,
  314.                         SizeDeterminer itsHSizeDet,
  315.                         SizeDeterminer itsVSizeDet,
  316.                         const TextStyle& itsTextStyle)
  317. {
  318.     TDocument * itsDocument = NULL;
  319.  
  320. #if qDebug
  321.     if ((itsSize.h > kMaxCoord) || (itsSize.v > kMaxCoord))
  322.     {
  323.         char msg[128];
  324.         
  325.         sprintf(msg, "The size in pixels of a TControl cannot exceed %ld\n", kMaxCoord);
  326.         ProgramBreak(msg);
  327.     }
  328. #endif
  329.  
  330.     if (itsSuperView)
  331.         itsDocument = itsSuperView->fDocument;
  332.  
  333.     this->IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  334.  
  335.     fTextStyle = itsTextStyle;
  336. } // TControl::IControl
  337.  
  338. //----------------------------------------------------------------------------------------
  339. // TControl::GetStandardSignature:
  340. //----------------------------------------------------------------------------------------
  341. #pragma segment MAWriteResource
  342.  
  343. IDType TControl::GetStandardSignature()    // override 
  344. {
  345.     return kStdControl;
  346. } // TControl::GetStandardSignature
  347.  
  348. //----------------------------------------------------------------------------------------
  349. // TControl::ReadFields:
  350. //----------------------------------------------------------------------------------------
  351. #pragma segment MAReadResource
  352.  
  353. void TControl::ReadFields(TStream* aStream)        // override 
  354. {
  355.     Inherited::ReadFields(aStream);
  356.  
  357.     FailInfo fi;
  358.     Try(fi)
  359.     {
  360.         fEventNumber = aStream->ReadLong();
  361.     
  362.         // set various flags
  363.         this->HiliteState(aStream->ReadBoolean(), kDontRedraw);
  364.         this->DimState(aStream->ReadBoolean(), kDontRedraw);
  365.         fSizeable = aStream->ReadBoolean();
  366.         
  367.         VRect itsInset;
  368.         aStream->ReadVRect(itsInset);
  369.         fInset = itsInset;
  370.         
  371.         fTextStyleRsrcID = aStream->ReadInteger();
  372.         if (fTextStyleRsrcID != kNoResource)
  373.         {
  374.             TextStyle itsTextStyle;
  375.             MAGetTextStyle(fTextStyleRsrcID, itsTextStyle);
  376.             fTextStyle = itsTextStyle;
  377.         }
  378.         
  379.         fPreferOutline = aStream->ReadBoolean();
  380.         fi.Success();
  381.     }
  382.     else
  383.     {
  384.         this->Free();
  385.         fi.ReSignal();
  386.     }
  387.  
  388. #if qDebug                                            
  389.     if ((fSize.h > kMaxCoord) || (fSize.v > kMaxCoord))
  390.     {
  391.         char msg[128];
  392.         
  393.         sprintf(msg, "The size in pixels of a TControl cannot exceed %ld\n", kMaxCoord);
  394.         ProgramBreak(gEmptyString);
  395.     }
  396. #endif
  397. } // TControl::ReadFields
  398.  
  399. //----------------------------------------------------------------------------------------
  400. // TControl::WriteFields:
  401. //----------------------------------------------------------------------------------------
  402. #pragma segment MAWriteResource
  403.  
  404. void TControl::WriteFields(TStream* aStream)        // override 
  405. {
  406.     Inherited::WriteFields(aStream);
  407.  
  408.     aStream->WriteLong(fEventNumber);                // write its fEventNumber
  409.  
  410.     aStream->WriteBoolean(fHilite);
  411.     aStream->WriteBoolean(fDimmed);
  412.     aStream->WriteBoolean(fSizeable);
  413.     
  414.     aStream->WriteVRect(fInset);                    // write its inset
  415.  
  416.     aStream->WriteInteger(fTextStyleRsrcID);
  417.  
  418.     aStream->WriteBoolean(fPreferOutline);
  419. } // TControl::WriteFields
  420.  
  421. //----------------------------------------------------------------------------------------
  422. // TControl::ComputeFrame:
  423. //----------------------------------------------------------------------------------------
  424. #pragma segment MAControlRes
  425.  
  426. void TControl::ComputeFrame(VRect& newFrame)// override
  427. {
  428.     Inherited::ComputeFrame(newFrame);
  429.     if (!fSizeable)
  430.     {
  431.         // …we need to adjust the bot/right offset
  432.         // If view is going to change size, then doesn't change control's actual size
  433.         fInset[botRight] += newFrame.GetSize() - fSize;
  434.     }
  435. } // TControl::ComputeFrame
  436.  
  437. //----------------------------------------------------------------------------------------
  438. // TControl::ContainsMouse:
  439. //----------------------------------------------------------------------------------------
  440. #pragma segment MAControlRes
  441.  
  442. Boolean TControl::ContainsMouse(const VPoint& theMouse)// override
  443. {
  444.     VRect aRect;
  445.     this->ControlArea(aRect);
  446.  
  447.     return aRect.Contains(theMouse) && Inherited::ContainsMouse(theMouse);
  448. } // TControl::ContainsMouse
  449.  
  450. //----------------------------------------------------------------------------------------
  451. // TControl::ControlArea:
  452. //----------------------------------------------------------------------------------------
  453. #pragma segment MAControlRes
  454.  
  455. void TControl::ControlArea(VRect& theArea)
  456. {
  457.     VRect itsExtent(this->GetExtent());
  458.     theArea = VRect(itsExtent[topLeft] + fInset[topLeft], itsExtent[botRight] - fInset[botRight]);
  459.  
  460.     CntlAdornment itsAdornment;
  461.     this->GetAdornment(itsAdornment);
  462.     if (macroIn(itsAdornment, adnShadow))
  463.     {
  464.         CPoint itsPenSize;
  465.         this->GetPenSize(itsPenSize);
  466.         theArea[botRight] -= VPoint(itsPenSize);
  467.     }
  468. } // TControl::ControlArea
  469.  
  470. //----------------------------------------------------------------------------------------
  471. // TControl::ControlQDArea:
  472. //----------------------------------------------------------------------------------------
  473. #pragma segment MAControlRes
  474.  
  475. CRect TControl::ControlQDArea()
  476. {
  477.     VRect theArea;
  478.     this->ControlArea(theArea);
  479.     return this->ViewToQDRect(theArea);
  480. } // TControl::ControlQDArea
  481.  
  482. //----------------------------------------------------------------------------------------
  483. // TControl::Dim:
  484. //----------------------------------------------------------------------------------------
  485. #pragma segment MAControlRes
  486.  
  487. void TControl::Dim()
  488. {
  489. #if qDebug
  490.     this->AssumeFocused();
  491. #endif
  492.  
  493.     PenPat(&qd.gray);
  494.     PenMode(patBic);
  495.     PaintRect(&this->ControlQDArea());
  496. } // TControl::Dim
  497.  
  498. //----------------------------------------------------------------------------------------
  499. // TControl::DimState:
  500. //----------------------------------------------------------------------------------------
  501. #pragma segment MAControlNonRes
  502.  
  503. void TControl::DimState(Boolean state, Boolean redraw)
  504. {
  505.     if (state != fDimmed)
  506.     {
  507.         fDimmed = state;
  508.         if (state)                                // dim adorner draws the dim state
  509.             this->AddAdorner(gDimAdorner, kAdornLast - 10, kDontRedraw);
  510.         else
  511.             this->DeleteAdorner(gDimAdorner, kDontRedraw);
  512.         if (redraw)
  513.             this->DrawContents();                // Draw change immediately
  514.     }
  515. } // TControl::DimState
  516.  
  517. //----------------------------------------------------------------------------------------
  518. // TControl::DoMouseCommand:
  519. //----------------------------------------------------------------------------------------
  520. #pragma segment MASelCommand
  521.  
  522. void TControl::DoMouseCommand(VPoint& theMouse,
  523.                               TToolboxEvent* ,
  524.                               CPoint)        // override 
  525. {
  526.     TControlTracker * aControlTracker = new TControlTracker;
  527.     aControlTracker->IControlTracker(this, theMouse);
  528.     this->PostCommand(aControlTracker);
  529. } // TControl::DoMouseCommand
  530.  
  531. //----------------------------------------------------------------------------------------
  532. // TControl::DoEvent:
  533. //----------------------------------------------------------------------------------------
  534. #pragma segment MAControlRes
  535.  
  536. void TControl::DoEvent(EventNumber eventNumber,
  537.                        TEventHandler* source,
  538.                        TEvent* event)    // override 
  539.  
  540. {
  541.     switch (eventNumber)
  542.     {
  543.         case mTurnOn:
  544.             this->HiliteState(TRUE,kRedraw);
  545.             break;
  546.         case mTurnOff:
  547.             this->HiliteState(FALSE,kRedraw);
  548.             break;
  549.         case mToggle:
  550.             this->HiliteState(!fHilite,kRedraw);
  551.             break;
  552.         default:
  553.             Inherited::DoEvent(eventNumber, source, event);
  554.             break;
  555.     }
  556. } // TControl::DoEvent
  557.  
  558. //----------------------------------------------------------------------------------------
  559. // TControl::Flash:
  560. //----------------------------------------------------------------------------------------
  561. #pragma segment DlgRes
  562.  
  563. void TControl::Flash()
  564. {
  565.     long dontCare;
  566.  
  567.     this->HiliteState(TRUE, kRedraw);
  568.     Delay(8, &dontCare);
  569.     this->HiliteState(FALSE, kRedraw);
  570. } // TControl::Flash
  571.  
  572. //----------------------------------------------------------------------------------------
  573. // TControl::Focus:
  574. //----------------------------------------------------------------------------------------
  575. #pragma segment MAControlRes
  576.  
  577. Boolean TControl::Focus()            // override 
  578. {
  579.     if (Inherited::Focus())
  580.     {
  581.         TextStyle aTextStyle = fTextStyle;
  582.         SetPortTextStyle(aTextStyle);
  583.         PenNormal();
  584.         return TRUE;
  585.     }
  586.     else
  587.         return FALSE;
  588. } // TControl::Focus
  589.  
  590. //----------------------------------------------------------------------------------------
  591. // TControl::Hilite:
  592. //----------------------------------------------------------------------------------------
  593. #pragma segment MAControlRes
  594.  
  595. void TControl::Hilite()
  596. {
  597. #if qDebug
  598.     this->AssumeFocused();
  599. #endif
  600.  
  601.     InvertRect(&this->ControlQDArea());
  602. } // TControl::Hilite
  603.  
  604. //----------------------------------------------------------------------------------------
  605. // TControl::HiliteState:
  606. //----------------------------------------------------------------------------------------
  607. #pragma segment MAControlNonRes
  608.  
  609. void TControl::HiliteState(Boolean state, Boolean redraw)
  610. {
  611.     if (state != fHilite)
  612.     {
  613.         fHilite = state;
  614.         if (state)                                // hilite adorner draws the hilite state
  615.             this->AddAdorner(gHiliteAdorner, kAdornLast - 5, kDontRedraw);
  616.         else
  617.             this->DeleteAdorner(gHiliteAdorner, kDontRedraw);
  618.         if (redraw && this->IsDrawable())
  619.             this->Hilite();
  620.     }
  621. } // TControl::HiliteState
  622.  
  623. //----------------------------------------------------------------------------------------
  624. // TControl::Inset:
  625. //----------------------------------------------------------------------------------------
  626. #pragma segment MAControlNonRes
  627.  
  628. void TControl::Inset(const VPoint& delta, Boolean redraw)
  629. {
  630.     if (fSizeable)
  631.     {
  632.         fInset += delta;
  633.  
  634.         if (redraw)
  635.             this->ForceRedraw();
  636.     }
  637. } // TControl::Inset
  638.  
  639. //----------------------------------------------------------------------------------------
  640. // TControl::InstallColor:
  641. //----------------------------------------------------------------------------------------
  642. #pragma segment MAControlNonRes
  643.  
  644. void TControl::InstallColor(const CRGBColor& theColor, Boolean redraw)
  645. {
  646.     fTextStyle.tsColor = theColor;
  647.     if (redraw)
  648.         this->DrawContents();
  649. } // TControl::InstallColor
  650.  
  651.  
  652. //----------------------------------------------------------------------------------------
  653. // TControl::InstallTextStyle:
  654. //----------------------------------------------------------------------------------------
  655. #pragma segment MAControlNonRes
  656.  
  657. void TControl::InstallTextStyle(const TextStyle& theTextStyle, Boolean redraw)
  658. {
  659.     fTextStyle = theTextStyle;
  660.     if (redraw)
  661.         this->DrawContents();
  662. } // TControl::InstallTextStyle
  663.  
  664. //----------------------------------------------------------------------------------------
  665. // TControl::IsDimmed:
  666. //----------------------------------------------------------------------------------------
  667. #pragma segment MAControlRes
  668.  
  669. Boolean TControl::IsDimmed()
  670. {
  671.     return fDimmed;
  672. } // TControl::IsDimmed
  673.  
  674. //----------------------------------------------------------------------------------------
  675. // TControl::SetFrame:
  676. //----------------------------------------------------------------------------------------
  677. #pragma segment MAControlNonRes
  678.  
  679. void TControl::SetFrame(const VRect& newFrame, Boolean invalidate)    // override
  680. {
  681.  
  682.     VPoint oldSize = fSize;
  683.  
  684.     Inherited::SetFrame(newFrame, invalidate);
  685.  
  686.     // If we need to invalidate, then invalidate the whole view rather than
  687.     // the difference between the old and new size.
  688.     if (invalidate && fSize != oldSize)
  689.         this->ForceRedraw();
  690. } // TControl::SetFrame
  691.  
  692. //----------------------------------------------------------------------------------------
  693. // TControl::GetAdornExtent:
  694. //----------------------------------------------------------------------------------------
  695. #pragma segment MAControlRes
  696.  
  697. void TControl::GetAdornExtent(VRect& itsAdornExtent)// override
  698. {
  699.     itsAdornExtent = this->GetExtent();
  700.  
  701.     CntlAdornment itsAdornment;
  702.     this->GetAdornment(itsAdornment);
  703.     if (macroIn(itsAdornment, adnShadow))
  704.     {
  705.         CPoint itsPenSize;
  706.         this->GetPenSize(itsPenSize);
  707.         itsAdornExtent[botRight] -= VPoint(itsPenSize);
  708.     }
  709. } // TControl::GetAdornExtent
  710.  
  711. //----------------------------------------------------------------------------------------
  712. // TControl::GetEventNumber:
  713. //----------------------------------------------------------------------------------------
  714. #pragma segment MAControlRes
  715.  
  716. EventNumber TControl::GetEventNumber()    // Override
  717. {
  718.     return fEventNumber;
  719. } // TControl::GetEventNumber
  720.  
  721. //----------------------------------------------------------------------------------------
  722. // TControl::SetAdornment:
  723. //----------------------------------------------------------------------------------------
  724. #pragma segment MAControlNonRes
  725.  
  726. void TControl::SetAdornment(/*CntlAdornment*/ short newAdornment, Boolean redraw)
  727. //!!! Using short rather than CntlAdornment because of a compiler bug
  728. {
  729.     TCompatibilityAdorner* itsAdorner = (TCompatibilityAdorner*)this->AdornerWithID(kCompatibilityAdorner);
  730.     if (itsAdorner == NULL) 
  731.     {
  732.         if (newAdornment != 0)
  733.         {
  734.             itsAdorner = new TCompatibilityAdorner;
  735.             itsAdorner->ICompatibilityAdorner(newAdornment);
  736.             this->AddAdorner(itsAdorner, kAdornAfter, redraw);
  737.         }
  738.     }
  739.     else
  740.     {
  741.         itsAdorner->fAdornment = newAdornment;
  742.         if (redraw)
  743.             this->ForceRedraw();
  744.     }
  745. } // TControl::SetAdornment
  746.  
  747. //----------------------------------------------------------------------------------------
  748. // TControl::GetAdornment:
  749. //----------------------------------------------------------------------------------------
  750. #pragma segment MAControlNonRes
  751.  
  752. void TControl::GetAdornment(CntlAdornment& itsAdornment)
  753. {
  754.     TAdorner* itsAdorner = this->AdornerWithID(kCompatibilityAdorner);
  755.     itsAdornment = 0; 
  756.     if (itsAdorner)
  757.         itsAdornment = ((TCompatibilityAdorner*)itsAdorner)->fAdornment;
  758. } // TControl::GetAdornment
  759.  
  760. //----------------------------------------------------------------------------------------
  761. // TControl::SetPenSize:
  762. //----------------------------------------------------------------------------------------
  763. #pragma segment MAControlNonRes
  764.  
  765. void TControl::SetPenSize(CPoint newPenSize)
  766. {
  767.     if (newPenSize != CPoint(1,1))
  768.     {
  769.         this->CreateDrawingEnvironment();
  770.         fDrawingEnvironment->fPenSize = newPenSize;
  771.     }
  772. } // TControl::SetPenSize
  773.  
  774. //----------------------------------------------------------------------------------------
  775. // TControl::GetPenSize:
  776. //----------------------------------------------------------------------------------------
  777. #pragma segment MAControlNonRes
  778.  
  779. void TControl::GetPenSize(CPoint& itsPenSize)
  780. {
  781.     if (fDrawingEnvironment)
  782.         itsPenSize = fDrawingEnvironment->fPenSize;
  783.     else
  784.         itsPenSize = CPoint(1,1);
  785. } // TControl::GetPenSize
  786.  
  787. //----------------------------------------------------------------------------------------
  788. // TControl::SetInset:
  789. //----------------------------------------------------------------------------------------
  790. #pragma segment MAControlNonRes
  791.  
  792. void TControl::SetInset(const VRect& newInset, Boolean redraw)
  793. {
  794.     if (fSizeable)
  795.     {
  796.         fInset = newInset;
  797.  
  798.         // this->Resize(fSize.Copy(), redraw);
  799.         if (redraw)
  800.             this->ForceRedraw();
  801.     }
  802. } // TControl::SetInset
  803.  
  804. //----------------------------------------------------------------------------------------
  805. // TControl::TrackFeedback:
  806. //----------------------------------------------------------------------------------------
  807. #pragma segment MASelCommand
  808.  
  809. void TControl::TrackFeedback(TrackPhase /* aTrackPhase */,
  810.                              const VPoint& /* anchorPoint */,
  811.                              const VPoint& /* previousPoint */,
  812.                              const VPoint& /* nextPoint */,
  813.                              Boolean /* mouseDidMove */,
  814.                              Boolean /* turnItOn */)
  815.  
  816. {
  817.     // do nothing
  818. } // TControl::TrackFeedback
  819.  
  820. //----------------------------------------------------------------------------------------
  821. // TControl::TrackMouse:
  822. //----------------------------------------------------------------------------------------
  823. #pragma segment MASelCommand
  824.  
  825. void TControl::TrackMouse(TrackPhase aTrackPhase,
  826.                           VPoint& /* anchorPoint */,
  827.                           VPoint& /* previousPoint */,
  828.                           VPoint& nextPoint,
  829.                           Boolean /* mouseDidMove */)
  830. {
  831.     switch (aTrackPhase)
  832.     {
  833.         case trackBegin:
  834.             this->HiliteState(TRUE, kRedraw);
  835.             break;
  836.         case trackContinue:
  837.             this->HiliteState(this->ContainsMouse(nextPoint), kRedraw);
  838.             break;
  839.         case trackEnd:
  840.             if (this->ContainsMouse(nextPoint))
  841.             {
  842.                 switch (fEventNumber)
  843.                 {
  844.                     // The defchoice determines different kinds of tracking behavior
  845.                     case mCheckBoxHit:
  846.                         // Toggle highlighting
  847.                         this->HandleEvent(mToggle,this,NULL);
  848.                         break;
  849.                     case mRadioHit:
  850.                         // Once it's on, it's on, until a cluster turns it off
  851.                         this->HandleEvent(mTurnOn,this,NULL);
  852.                         break;
  853.                     default:
  854.                         // Button action. Turn off highlighting.
  855.                         this->HandleEvent(mTurnOff,this,NULL);
  856.                         break;
  857.                 }
  858.                 this->HandleEvent(fEventNumber, this, NULL);
  859.             }
  860.             break;
  861.     }
  862. } // TControl::TrackMouse
  863.  
  864.  
  865. //========================================================================================
  866. // CLASS TCtlMgr
  867. //========================================================================================
  868. #undef Inherited
  869. #define Inherited TControl
  870.  
  871. #pragma segment MAOpen
  872. MA_DEFINE_CLASS_M1(TCtlMgr, Inherited);
  873.  
  874. //----------------------------------------------------------------------------------------
  875. // TCtlMgr constructor
  876. //----------------------------------------------------------------------------------------
  877. #pragma segment MAOpen
  878.  
  879. TCtlMgr::TCtlMgr()
  880. {
  881.     fCMgrControl = NULL;
  882.  
  883.     // These MUST be initialized because SetLongValues tests each new value against 
  884.     // the old value before doing anything. If the fLongMax value should happen to
  885.     // have a (bogus - uninitialized) value that matches itsMax, fBitsToShift won't 
  886.     // be initialized and the control manager control will behave erratically.
  887.     fBitsToShift = 0;
  888.     fLongVal = 0;
  889.     fLongMin = 0;
  890.     fLongMax = 0;
  891.     fProcID = 0;
  892. } // TCtlMgr::TCtlMgr
  893.  
  894. //----------------------------------------------------------------------------------------
  895. // TCtlMgr::ICtlMgr:
  896. //----------------------------------------------------------------------------------------
  897. #pragma segment MAOpen
  898.  
  899. void TCtlMgr::ICtlMgr(TView* itsSuperView,
  900.                       const VPoint& itsLocation,
  901.                       const VPoint& itsSize,
  902.                       SizeDeterminer itsHSizeDet,
  903.                       SizeDeterminer itsVSizeDet,
  904.                       const CStr255& itsTitle,
  905.                       long itsVal,
  906.                       long itsMin,
  907.                       long itsMax,
  908.                       short itsProcID,
  909.                       const TextStyle& itsTextStyle)
  910. {
  911.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTextStyle);
  912.  
  913.     FailInfo fi;
  914.     Try(fi)
  915.     {
  916.         this->CreateCMgrControl(itsTitle, itsVal, itsMin, itsMax, itsProcID);
  917.         fi.Success();
  918.     }
  919.     else
  920.     {
  921.         this->Free();
  922.         fi.ReSignal();
  923.     }
  924. } // TCtlMgr::ICtlMgr
  925.  
  926. //----------------------------------------------------------------------------------------
  927. // TCtlMgr::Clone:
  928. //----------------------------------------------------------------------------------------
  929. #pragma segment MAControlNonRes
  930.  
  931. TObject* TCtlMgr::Clone()                // override 
  932. {
  933.     MAVolatileInit(TCtlMgr*, aClonedCtlMgr, (TCtlMgr *)(Inherited::Clone()));
  934.     
  935.     if (fCMgrControl)
  936.     {
  937.         // Copy the control values to locals and then set the values in the TCtlMgr to
  938.         // zero. The SetLongxxx routines check to see if the control values have changed
  939.         // before actual changing the toolbox control.
  940.         
  941.         aClonedCtlMgr->fLongMin = aClonedCtlMgr->fLongMax = aClonedCtlMgr->fLongVal = 0;
  942.  
  943.         CStr255 contrlTitle;
  944.         GetControlTitle(fCMgrControl, contrlTitle);
  945.  
  946.         FailInfo fi;
  947.         Try(fi)
  948.         {
  949.             aClonedCtlMgr->CreateCMgrControl(contrlTitle, fLongVal, fLongMin, fLongMax, fProcID);
  950.             fi.Success();
  951.         }
  952.         else
  953.         {
  954.             aClonedCtlMgr->Free();
  955.             fi.ReSignal();
  956.         }
  957.     }
  958.  
  959.     return aClonedCtlMgr;
  960. } // TCtlMgr::Clone
  961.  
  962. //----------------------------------------------------------------------------------------
  963. // TCtlMgr::Free:
  964. //----------------------------------------------------------------------------------------
  965. #pragma segment MAClose
  966.  
  967. TCtlMgr::~TCtlMgr()
  968. {
  969.     if (fCMgrControl)
  970.     {
  971.         this->SetCMgrVisibility(FALSE);            // This insures that HideControl, which
  972.                                                 // will be called by SizeControl, doesn't
  973.                                                 // do anything. HideControl seems to have
  974.                                                 // some problems with large (~>
  975.                                                 // 14000x14000)
  976.         SizeControl(fCMgrControl, 0, 0);        // Prevent CMgr from erasing the control!
  977.         DisposeControl(fCMgrControl);
  978.         fCMgrControl = NULL;                    // So BeInPort and others will be happy!
  979.     }
  980. } // TCtlMgr::Free
  981.  
  982. //----------------------------------------------------------------------------------------
  983. // TCtlMgr::BeInPort:
  984. //----------------------------------------------------------------------------------------
  985. #pragma segment MAControlNonRes
  986.  
  987. void TCtlMgr::BeInPort(GrafPtr itsPort)    // override 
  988. {
  989.     Inherited::BeInPort(itsPort);
  990.     
  991.     if (fCMgrControl)
  992.     {
  993.         WindowRef itsNewControlOwner;
  994.         if (!itsPort)
  995.         {
  996.             this->SetCMgrVisibility(FALSE);
  997.             itsNewControlOwner = (WindowRef)gWorkPort;
  998.         }
  999.         else
  1000.         {
  1001.             this->SetCMgrVisibility(TRUE);
  1002.             itsNewControlOwner = (WindowRef)itsPort;
  1003.         }
  1004.         
  1005.         //
  1006.         // Get the control pointing at the owning window
  1007.         //
  1008.         WindowRef itsOldControlOwner = (*fCMgrControl)->contrlOwner;
  1009.         (*fCMgrControl)->contrlOwner = gWorkPort;    // in case it's not anywhere else
  1010.         
  1011.         //
  1012.         // Get the control off the control list of the old owner
  1013.         //
  1014.         if (itsOldControlOwner)
  1015.         {
  1016.             // first control on list
  1017.             if (((WindowPeek)itsOldControlOwner)->controlList == fCMgrControl)
  1018.             {
  1019.                 ((WindowPeek)itsOldControlOwner)->controlList = (*fCMgrControl)->nextControl;
  1020.             }
  1021.             else
  1022.             {
  1023.                 ControlHandle currentControl = ((WindowPeek)itsOldControlOwner)->controlList;
  1024.                 while (currentControl)
  1025.                 {
  1026.                     if ((*currentControl)->nextControl == fCMgrControl)
  1027.                     {
  1028.                         (*currentControl)->nextControl = (*fCMgrControl)->nextControl;
  1029.                         break;
  1030.                     }
  1031.                     currentControl = (*currentControl)->nextControl;
  1032.                 }
  1033.             }
  1034.         }
  1035.         
  1036.         //
  1037.         // and on to the control list of the new owner
  1038.         //
  1039.         if (itsNewControlOwner)
  1040.         {
  1041.             TWindow* itsWindow = this->GetWindow();
  1042.              if (itsWindow && itsWindow->fWMgrWindow == itsNewControlOwner)
  1043.             {
  1044.             #if 0
  1045.                 (*fCMgrControl)->nextControl = GetControlOwningWindowControlList(itsNewControlOwner);
  1046.                 GetControlOwningWindowControlList(itsNewControlOwner) = fCMgrControl;
  1047.             #else
  1048.     
  1049.                 (*fCMgrControl)->nextControl = ((WindowPeek)itsNewControlOwner)->controlList;
  1050.                 ((WindowPeek)itsNewControlOwner)->controlList = fCMgrControl;
  1051.             #endif
  1052.     
  1053.     
  1054.                 (*fCMgrControl)->contrlOwner = itsNewControlOwner;
  1055.             }
  1056.         }
  1057.  
  1058.     }
  1059. } // TCtlMgr::BeInPort
  1060.  
  1061. //----------------------------------------------------------------------------------------
  1062. // TCtlMgr::CreateCMgrControl:
  1063. //----------------------------------------------------------------------------------------
  1064. #pragma segment MAOpen
  1065.  
  1066. void TCtlMgr::CreateCMgrControl(const CStr255& itsTitle,
  1067.                                 long itsVal,
  1068.                                 long itsMin,
  1069.                                 long itsMax,
  1070.                                 short itsProcID)
  1071. {
  1072.     TWindow* itsTWindow = this->GetWindow();
  1073.     WindowRef itsWindow = itsTWindow ? itsTWindow->fWMgrWindow : gWorkPort;
  1074.  
  1075.     fProcID = itsProcID;
  1076.  
  1077.     ControlRef aCMgrControl = NewControl(itsWindow, this->ControlQDArea(), itsTitle, FALSE, 0, 0, 0, itsProcID, (long)this);
  1078.     FailNIL(aCMgrControl);
  1079.     
  1080.     fCMgrControl = aCMgrControl;
  1081.     this->DimState(fDimmed, kDontRedraw);
  1082.     this->HiliteState(fHilite, kDontRedraw);
  1083.  
  1084.     // Remember, the control was created with zeros, fix it up.
  1085.     this->SetLongValues(itsVal, itsMin, itsMax, kDontRedraw);
  1086.  
  1087.     this->SetCMgrVisibility(itsWindow != gWorkPort);
  1088. } // TCtlMgr::CreateCMgrControl
  1089.  
  1090. //----------------------------------------------------------------------------------------
  1091. // TCtlMgr::InstallColor:
  1092. //----------------------------------------------------------------------------------------
  1093. #pragma segment MAControlNonRes
  1094.  
  1095. void TCtlMgr::InstallColor(const CRGBColor& theColor, Boolean redraw)
  1096. {
  1097.     if ((qNeedsColorQD || HasColorQD()) && fCMgrControl)
  1098.     {
  1099.         // retrieve the control's color table
  1100.         AuxCtlHandle itsAuxCtlHandle;
  1101.         Boolean hasAuxCtl = GetAuxiliaryControlRecord(fCMgrControl, &itsAuxCtlHandle);
  1102.         FailNIL(itsAuxCtlHandle);
  1103.         CCTabHandle colorTableHandle = (*itsAuxCtlHandle)->acCTable;
  1104.         FailNIL(colorTableHandle);
  1105.         
  1106.         // determine if the control color table needs to be changed
  1107.         Boolean changeColorTable = TRUE;
  1108.  
  1109.         // The ctSize field defines the number of elements in the table, minus one.
  1110.         for (short i = 0; i <= (*colorTableHandle)->ctSize; ++i)
  1111.         {
  1112.             if ((*colorTableHandle)->ctTable[i].value == cFrameColor)
  1113.             {
  1114.                 changeColorTable = CRGBColor((*colorTableHandle)->ctTable[i].rgb) != theColor;
  1115.                 break;
  1116.             }
  1117.         }
  1118.  
  1119.         // modify the color table if necessary
  1120.         if (changeColorTable)
  1121.         {
  1122.             PermHandToHand((Handle &) colorTableHandle);
  1123.     
  1124.             // Parse the color table, and make the appropriate settings.
  1125.             // The ctSize field defines the number of elements in the table, minus one.
  1126.             for (short i = 0; i <= (*colorTableHandle)->ctSize; ++i)
  1127.             {
  1128.                 switch ((*colorTableHandle)->ctTable[i].value)
  1129.                 {
  1130.                     case cFrameColor:
  1131.                     case cTextColor:
  1132.                         (*colorTableHandle)->ctTable[i].rgb = theColor;
  1133.                         break;
  1134.                     case cThumbColor:
  1135.                     case cBodyColor:
  1136.                         break;    // do nothing - InstallColor only affects the "fore" color
  1137.                 }
  1138.             }
  1139.     
  1140.             // set the new color table
  1141.             CWhileFocused itsWhileFocused(this, redraw);
  1142.             CWhileOutlinePreferred setOP(fPreferOutline);
  1143.  
  1144.             SetControlColor(fCMgrControl, colorTableHandle);
  1145.         }
  1146.     }
  1147.  
  1148.     Inherited::InstallColor(theColor, redraw);
  1149. } // TCtlMgr::InstallColor
  1150.  
  1151.  
  1152. //----------------------------------------------------------------------------------------
  1153. // TCtlMgr::DimState:
  1154. //----------------------------------------------------------------------------------------
  1155. #pragma segment MAControlNonRes
  1156.  
  1157. void TCtlMgr::DimState(Boolean state, Boolean redraw)    // override 
  1158. {
  1159.     if (fCMgrControl && (*fCMgrControl)->contrlHilite != (state ? 255 : 0))
  1160.     {
  1161.         CWhileFocused itsWhileFocused(this, redraw);
  1162.         CWhileOutlinePreferred setOP(fPreferOutline);
  1163.  
  1164.         HiliteControl(fCMgrControl, state ? 255 : 0);
  1165.     }
  1166.     fDimmed = state;
  1167. } // TCtlMgr::DimState
  1168.  
  1169. //----------------------------------------------------------------------------------------
  1170. // TCtlMgr::DoMouseCommand:
  1171. //----------------------------------------------------------------------------------------
  1172. #pragma segment MASelCommand
  1173.  
  1174. void TCtlMgr::DoMouseCommand(VPoint& theMouse,
  1175.                              TToolboxEvent* /* event */,
  1176.                              CPoint /* hysteresis */)        // override
  1177. {
  1178.     CPoint theQDMouse(this->ViewToQDPt(theMouse));
  1179.  
  1180.     if (fCMgrControl)
  1181.     {
  1182.         CWhileFocused itsWhileFocused(this, kRedraw);
  1183.         if (TestControl(fCMgrControl, theQDMouse) != 0)
  1184.         {
  1185.             CWhileOutlinePreferred setOP(fPreferOutline);
  1186.  
  1187.             short trackResult = TrackControl(fCMgrControl, theQDMouse, (ControlActionUPP)(-1));
  1188.             
  1189.             if (trackResult != 0)
  1190.             {
  1191.                 long newLongValue;
  1192.                 
  1193.                 if (this->GetVal() == this->GetMax())
  1194.                     newLongValue = fLongMax;
  1195.                 else
  1196.                     newLongValue = ((long)GetVal() << fBitsToShift);
  1197.                 this->SetLongVal(newLongValue, kRedraw);
  1198.                 
  1199.                 this->HandleEvent(fEventNumber, this, NULL);
  1200.  
  1201.                 gDispatcher->InvalidateMouseRegions();
  1202.             }
  1203.         }
  1204.     }
  1205. } // TCtlMgr::DoMouseCommand
  1206.  
  1207. //----------------------------------------------------------------------------------------
  1208. // TCtlMgr::Draw:
  1209. //----------------------------------------------------------------------------------------
  1210. #pragma segment MAControlRes
  1211.  
  1212. void TCtlMgr::Draw(const VRect& area)    // override 
  1213. {
  1214.     if (this->IsCMgrVisible())
  1215.     {
  1216. #if qDebug
  1217.         this->AssumeFocused();
  1218. #endif
  1219.         // for controls, spool the picture and draw that to overcome font problems
  1220.         PicHandle aPH = NULL;
  1221.         if (gPrinting)
  1222.         {
  1223.             GrafPtr printPort = qd.thePort;
  1224.             // spool picture, take care as this will call TCtlMgr.Draw()
  1225.             gPrinting = FALSE;
  1226.             aPH = this->AsPictForPrinting();
  1227.             gPrinting = TRUE;
  1228.             // if success, print this picture
  1229.             if (aPH)
  1230.             {
  1231.                 SetPort(printPort);
  1232.                 DrawPicture(aPH, &this->GetQDExtent());
  1233.                 DisposeIfPicHandle(aPH);
  1234.             }
  1235.         }
  1236.         
  1237.         // if spooling failed, or not printing, use Draw1Control()
  1238.         if (! gPrinting || aPH == NULL)
  1239.         {
  1240.             // save/set/reset the port in case we're imaging in some other port 
  1241.             WindowRef savedOwner = (*fCMgrControl)->contrlOwner;
  1242.             (*fCMgrControl)->contrlOwner = (WindowRef)qd.thePort;    //NOTE: !!! Still needs proper fix, SRF
  1243.         
  1244.             CWhileFocused itsWhileFocused(this, kRedraw);
  1245.             CWhileOutlinePreferred setOP(fPreferOutline);
  1246.  
  1247.             PenNormal();
  1248.             Draw1Control(fCMgrControl);
  1249.     
  1250.             // restore control owner
  1251.             (*fCMgrControl)->contrlOwner = savedOwner;
  1252.         }
  1253.     }
  1254.  
  1255.     Inherited::Draw(area);                        // to get adornment 
  1256. } // TCtlMgr::Draw
  1257.  
  1258. //----------------------------------------------------------------------------------------
  1259. // TCtlMgr::AsPictForPrinting:
  1260. //----------------------------------------------------------------------------------------
  1261. #pragma segment MAControlRes
  1262.  
  1263. PicHandle TCtlMgr::AsPictForPrinting()
  1264. {
  1265.     // this code is very similar to TView.AsPict(), but to make sure nothing else breaks,
  1266.     // I made it into a separate method.
  1267.     
  1268.     MAVolatileInit(PicHandle, pHndl, NULL);
  1269.     MAVolatileInit(Boolean, pictureIsOpen, FALSE);
  1270.  
  1271.     CRect aRect(qd.thePort->portRect);
  1272.     
  1273.     SetPortWindowPort(gWorkPort);
  1274.     PortSize(aRect.GetLength(hSel), aRect.GetLength(vSel));
  1275.     MovePortTo(aRect.right, aRect.top);
  1276.  
  1277.     this->InvalidateFocus();
  1278.     gDrawingPictScrap = TRUE;
  1279.     gDrawingPictScrapView = this;
  1280.     SetPortWindowPort(gWorkPort);
  1281.     this->BeInPort((GrafPtr)GetWindowPort(gWorkPort));
  1282.  
  1283.     FailInfo fi;
  1284.     Try(fi)
  1285.     {
  1286.         if (this->Focus())
  1287.         {
  1288.             CRect qdExtent(this->GetQDExtent());
  1289.             pHndl = OpenPicture(qdExtent);
  1290.             pictureIsOpen = TRUE;                // Failure handler needs to close it 
  1291.             FailNIL(pHndl);
  1292.  
  1293.             ClipRect(qdExtent);
  1294.             this->DrawContents();
  1295.             ClosePicture();
  1296.             pictureIsOpen = FALSE;                // Failure handler doesn't need to close it 
  1297.  
  1298.             // On the 128K ROMs the picFrame will be empty if drawing the
  1299.             // picture failed.    On the 64K ROM's QuickDraw simply bombs.
  1300.             if (((CRect &) (*pHndl)->picFrame).Empty())
  1301.             {
  1302. #if qDebug
  1303.                 fprintf(stderr, "Picture frame is empty!\n");
  1304. #endif
  1305.                 FailOSErr(memFullErr);
  1306.             }
  1307.  
  1308.             this->InvalidateFocus();
  1309.         }
  1310. #if qDebug
  1311.         else                                    // can't focus 
  1312.             ProgramBreak("Can't focus view while spooling picture for printing");
  1313. #endif
  1314.  
  1315.         fi.Success();
  1316.     }
  1317.     else
  1318.     {
  1319.         if (pHndl)
  1320.         {
  1321.             if (pictureIsOpen)
  1322.                 ClosePicture();
  1323.             pHndl = DisposeIfPicHandle(pHndl);
  1324.         }
  1325.     }
  1326.  
  1327.     SetPortWindowPort(gWorkPort);
  1328.     PortSize(0, 0);
  1329.     gDrawingPictScrap = FALSE;
  1330.     gDrawingPictScrapView = NULL;
  1331.  
  1332.     // if NULL is returned, Draw1Control() will be used
  1333.     return pHndl;
  1334.     
  1335. } // TCtlMgr::AsPictForPrinting
  1336.  
  1337. //----------------------------------------------------------------------------------------
  1338. // TCtlMgr::IsCMgrVisible:
  1339. //----------------------------------------------------------------------------------------
  1340. #pragma segment MAControlRes
  1341.  
  1342. Boolean TCtlMgr::IsCMgrVisible()
  1343. {
  1344.     return (fCMgrControl && ((*fCMgrControl)->contrlVis == 255));
  1345. } // TCtlMgr::IsCMgrVisible
  1346.  
  1347. //----------------------------------------------------------------------------------------
  1348. // TCtlMgr::GetMax:
  1349. //----------------------------------------------------------------------------------------
  1350. #pragma segment MAControlRes
  1351.  
  1352. short TCtlMgr::GetMax()
  1353. {
  1354.     return fCMgrControl ? GetControlMaximum(fCMgrControl) : 0;
  1355. } // TCtlMgr::GetMax
  1356.  
  1357. //----------------------------------------------------------------------------------------
  1358. // TCtlMgr::GetMin:
  1359. //----------------------------------------------------------------------------------------
  1360. #pragma segment MAControlRes
  1361.  
  1362. short TCtlMgr::GetMin()
  1363. {
  1364.     return fCMgrControl ? GetControlMinimum(fCMgrControl) : 0;
  1365. } // TCtlMgr::GetMin
  1366.  
  1367. //----------------------------------------------------------------------------------------
  1368. // TCtlMgr::GetText:
  1369. //----------------------------------------------------------------------------------------
  1370. #pragma segment MAControlRes
  1371.  
  1372. void TCtlMgr::GetText(CStr255& theText)
  1373. {
  1374.     if (fCMgrControl)
  1375.         GetControlTitle(fCMgrControl, theText);
  1376.     else
  1377.         theText.Empty();
  1378. } // TCtlMgr::GetText
  1379.  
  1380. //----------------------------------------------------------------------------------------
  1381. // TCtlMgr::GetVal:
  1382. //----------------------------------------------------------------------------------------
  1383. #pragma segment MAControlRes
  1384.  
  1385. short TCtlMgr::GetVal()
  1386. {
  1387.     return fCMgrControl ? GetControlValue(fCMgrControl) : 0;
  1388. } // TCtlMgr::GetVal
  1389.  
  1390. //----------------------------------------------------------------------------------------
  1391. // TCtlMgr::GetVariant:
  1392. //----------------------------------------------------------------------------------------
  1393. #pragma segment MAControlRes
  1394.  
  1395. short TCtlMgr::GetVariant()
  1396. {
  1397.     return fCMgrControl ? GetControlVariant(fCMgrControl) : 0;
  1398. } // TCtlMgr::GetVariant
  1399.  
  1400. //----------------------------------------------------------------------------------------
  1401. // TCtlMgr::HiliteState:
  1402. //----------------------------------------------------------------------------------------
  1403. #pragma segment MAControlNonRes
  1404.  
  1405. void TCtlMgr::HiliteState(Boolean state, Boolean redraw)    // override 
  1406. {
  1407.     // if the control is dimmed, leave it alone!
  1408.     if (fCMgrControl && (*fCMgrControl)->contrlHilite != 255 && fHilite != (*fCMgrControl)->contrlHilite != (state * 10))
  1409.     {
  1410.         CWhileFocused itsWhileFocused(this, redraw);
  1411.         CWhileOutlinePreferred setOP(fPreferOutline);
  1412.  
  1413.         HiliteControl(fCMgrControl, state * 10);
  1414.     }
  1415.     fHilite = state;
  1416. } // TCtlMgr::HiliteState
  1417.  
  1418. //----------------------------------------------------------------------------------------
  1419. // TCtlMgr::Inset:
  1420. //----------------------------------------------------------------------------------------
  1421. #pragma segment MAControlNonRes
  1422.  
  1423. void TCtlMgr::Inset(const VPoint& delta, Boolean redraw)    // override 
  1424. {
  1425.     Inherited::Inset(delta, kDontRedraw);
  1426.     
  1427.     this->AdjustCtlMgrControl(redraw);
  1428. } // TCtlMgr::Inset
  1429.  
  1430. //----------------------------------------------------------------------------------------
  1431. // TCtlMgr::SetInset:
  1432. //----------------------------------------------------------------------------------------
  1433. #pragma segment MAControlNonRes
  1434.  
  1435. void TCtlMgr::SetInset(const VRect& newInset, Boolean redraw)
  1436. {
  1437.     Inherited::SetInset(newInset, kDontRedraw);
  1438.     
  1439.     this->AdjustCtlMgrControl(redraw);
  1440. } // TCtlMgr::SetInset
  1441.  
  1442. //----------------------------------------------------------------------------------------
  1443. // TCtlMgr::AdjustCtlMgrControl:
  1444. //----------------------------------------------------------------------------------------
  1445. #pragma segment MAControlNonRes
  1446.  
  1447. void TCtlMgr::AdjustCtlMgrControl(Boolean redraw)
  1448. {
  1449.     if (fCMgrControl)
  1450.     {
  1451.         CWhileFocused itsWhileFocused(this, redraw);
  1452.         CWhileOutlinePreferred setOP(fPreferOutline);
  1453.  
  1454.         CRect qdArea(this->ControlQDArea());
  1455.     
  1456.         MoveControl(fCMgrControl, qdArea.left, qdArea.top);
  1457.         if (fSizeable)
  1458.             SizeControl(fCMgrControl, abs(qdArea.GetLength(hSel)), abs(qdArea.GetLength(vSel)));
  1459.     }
  1460. } // TCtlMgr::AdjustCtlMgrControl
  1461.  
  1462. //----------------------------------------------------------------------------------------
  1463. // TCtlMgr::SetFrame:
  1464. //----------------------------------------------------------------------------------------
  1465. #pragma segment MAControlNonRes
  1466.  
  1467. void TCtlMgr::SetFrame(const VRect& newFrame, Boolean invalidate)    // override 
  1468. {
  1469.     VRect oldFrame(this->GetFrame());
  1470.  
  1471.     Inherited::SetFrame(newFrame, invalidate);
  1472.  
  1473.     if (newFrame != oldFrame)
  1474.         AdjustCtlMgrControl(invalidate);
  1475. } // TCtlMgr::SetFrame
  1476.  
  1477. //----------------------------------------------------------------------------------------
  1478. // TCtlMgr::SetCMgrVisibility:
  1479. //----------------------------------------------------------------------------------------
  1480. #pragma segment MAControlRes
  1481.  
  1482. Boolean TCtlMgr::SetCMgrVisibility(Boolean beVisible)
  1483. {
  1484.     Boolean returnVal = this->IsCMgrVisible();
  1485.  
  1486.     if (fCMgrControl)
  1487.         if (beVisible)
  1488.             (*fCMgrControl)->contrlVis = 255;
  1489.         else
  1490.             (*fCMgrControl)->contrlVis = 0;
  1491.     
  1492.     return returnVal;
  1493. } // TCtlMgr::SetCMgrVisibility
  1494.  
  1495. //----------------------------------------------------------------------------------------
  1496. // TCtlMgr::Show:
  1497. //----------------------------------------------------------------------------------------
  1498. #pragma segment MAControlRes
  1499.  
  1500. void TCtlMgr::Show(Boolean state, Boolean redraw)
  1501. {
  1502.     this->SetCMgrVisibility(state);
  1503.     
  1504.     Inherited::Show(state, redraw);
  1505. } // TCtlMgr::Show
  1506.  
  1507. //----------------------------------------------------------------------------------------
  1508. // TCtlMgr::SetMax:
  1509. //----------------------------------------------------------------------------------------
  1510. #pragma segment MAControlRes
  1511.  
  1512. void TCtlMgr::SetMax(short itsMax, Boolean redraw)
  1513. {
  1514.     if (fCMgrControl && GetControlMaximum(fCMgrControl) != itsMax)
  1515.     {
  1516.         CWhileFocused itsWhileFocused(this, redraw);
  1517.         CWhileOutlinePreferred setOP(fPreferOutline);
  1518.  
  1519.         SetControlMaximum(fCMgrControl, itsMax);
  1520.     }
  1521. } // TCtlMgr::SetMax
  1522.  
  1523. //----------------------------------------------------------------------------------------
  1524. // TCtlMgr::SetMin:
  1525. //----------------------------------------------------------------------------------------
  1526. #pragma segment MAControlRes
  1527.  
  1528. void TCtlMgr::SetMin(short itsMin, Boolean redraw)
  1529. {
  1530.     if (fCMgrControl && GetControlMinimum(fCMgrControl) != itsMin)
  1531.     {
  1532.         CWhileFocused itsWhileFocused(this, redraw);
  1533.         CWhileOutlinePreferred setOP(fPreferOutline);
  1534.  
  1535.         SetControlMinimum(fCMgrControl, itsMin);
  1536.     }
  1537. } // TCtlMgr::SetMin
  1538.  
  1539. //----------------------------------------------------------------------------------------
  1540. // TCtlMgr::SetText:
  1541. //----------------------------------------------------------------------------------------
  1542. #pragma segment MAControlNonRes
  1543.  
  1544. void TCtlMgr::SetText(const CStr255& itsText, Boolean redraw)
  1545. {
  1546.     CStr255 currentText;
  1547.  
  1548.     if (fCMgrControl)
  1549.     {
  1550.         this->GetText(currentText);
  1551.         if (CompareStrings(currentText, itsText) != 0)
  1552.         {
  1553.             CWhileFocused itsWhileFocused(this, redraw);
  1554.             CWhileOutlinePreferred setOP(fPreferOutline);
  1555.     
  1556.             SetControlTitle(fCMgrControl, itsText);
  1557.             if (this->IsFocused())                    // we were focused if redraw was true
  1558.             {
  1559.                 CRect r = (*(fCMgrControl))->contrlRect;
  1560.                 this->ValidateRect(r);                // Because Control Manager invalidates it.
  1561.             }
  1562.         }
  1563.     }
  1564. } // TCtlMgr::SetText
  1565.  
  1566. //----------------------------------------------------------------------------------------
  1567. // TCtlMgr::SetVal:
  1568. //----------------------------------------------------------------------------------------
  1569. #pragma segment MAControlRes
  1570.  
  1571. void TCtlMgr::SetVal(short newVal, Boolean redraw)
  1572. {
  1573.     if (fCMgrControl && GetControlValue(fCMgrControl) != newVal)
  1574.     {
  1575.         CWhileFocused itsWhileFocused(this, redraw);
  1576.         CWhileOutlinePreferred setOP(fPreferOutline);
  1577.  
  1578.         SetControlValue(fCMgrControl, newVal);
  1579.     }
  1580. } // TCtlMgr::SetVal
  1581.  
  1582. //----------------------------------------------------------------------------------------
  1583. // TCtlMgr::SetValues:
  1584. //----------------------------------------------------------------------------------------
  1585. #pragma segment MAControlRes
  1586.  
  1587. void TCtlMgr::SetValues(short itsVal,
  1588.                         short itsMin,
  1589.                         short itsMax,
  1590.                         Boolean redraw)
  1591. {
  1592.     if (fCMgrControl)
  1593.     {
  1594.         CWhileFocused itsWhileFocused(this, redraw);
  1595.         CWhileOutlinePreferred setOP(fPreferOutline);
  1596.  
  1597.         SetControlMinimum(fCMgrControl, itsMin);
  1598.         SetControlMaximum(fCMgrControl, itsMax);
  1599.         SetControlValue(fCMgrControl, itsVal);
  1600.     }
  1601. } // TCtlMgr::SetValues
  1602.  
  1603. //----------------------------------------------------------------------------------------
  1604. // TCtlMgr::GetLongMax:
  1605. //----------------------------------------------------------------------------------------
  1606. #pragma segment MAControlRes
  1607.  
  1608. VCoordinate TCtlMgr::GetLongMax()
  1609. {
  1610.     return fLongMax;
  1611. } // TCtlMgr::GetLongMax
  1612.  
  1613. //----------------------------------------------------------------------------------------
  1614. // TCtlMgr::GetLongMin:
  1615. //----------------------------------------------------------------------------------------
  1616. #pragma segment MAControlRes
  1617.  
  1618. VCoordinate TCtlMgr::GetLongMin()
  1619. {
  1620.     return fLongMin;
  1621. } // TCtlMgr::GetLongMin
  1622.  
  1623. //----------------------------------------------------------------------------------------
  1624. // TCtlMgr::GetLongVal:
  1625. //----------------------------------------------------------------------------------------
  1626. #pragma segment MAControlRes
  1627.  
  1628. VCoordinate TCtlMgr::GetLongVal()
  1629. {
  1630.     return fLongVal;
  1631. } // TCtlMgr::GetLongVal
  1632.  
  1633. //----------------------------------------------------------------------------------------
  1634. // TCtlMgr::SetLongMax:
  1635. //----------------------------------------------------------------------------------------
  1636. #pragma segment MAControlRes
  1637.  
  1638. void TCtlMgr::SetLongMax(VCoordinate itsMax, Boolean redraw)
  1639. {
  1640.     if (itsMax != fLongMax)
  1641.     {
  1642.         fLongMax = itsMax;
  1643.         fBitsToShift = 0;
  1644.         while (itsMax > SHRT_MAX)
  1645.         {
  1646.             itsMax = ((itsMax) >> 1);
  1647.             ++fBitsToShift;
  1648.         }
  1649.         this->SetMax((short)itsMax, redraw);
  1650.         if (fLongMax < fLongVal) {
  1651.             this->SetLongVal(fLongMax, redraw);
  1652.         }
  1653.     }
  1654. } // TCtlMgr::SetLongMax
  1655.  
  1656. //----------------------------------------------------------------------------------------
  1657. // TCtlMgr::SetLongMin:
  1658. //----------------------------------------------------------------------------------------
  1659. #pragma segment MAControlRes
  1660.  
  1661. void TCtlMgr::SetLongMin(VCoordinate itsMin, Boolean redraw)
  1662. {
  1663.     if (itsMin != fLongMin)
  1664.     {
  1665.         fLongMin = itsMin;
  1666.         this->SetMin((short)(itsMin >> fBitsToShift), redraw);
  1667.         if (fLongMin > fLongVal) {
  1668.             this->SetLongVal(fLongMin, redraw);
  1669.         }
  1670.     }
  1671. } // TCtlMgr::SetLongMin
  1672.  
  1673. //----------------------------------------------------------------------------------------
  1674. // TCtlMgr::SetLongVal:
  1675. //----------------------------------------------------------------------------------------
  1676. #pragma segment MAControlRes
  1677.  
  1678. void TCtlMgr::SetLongVal(VCoordinate itsVal, Boolean redraw)
  1679. {
  1680.     itsVal = MinMax(fLongMin, itsVal, fLongMax);
  1681.     if (itsVal != fLongVal)
  1682.     {
  1683.         fLongVal = itsVal;
  1684.         this->SetVal((short)(itsVal >> fBitsToShift), redraw);
  1685.     }
  1686. } // TCtlMgr::SetLongVal
  1687.  
  1688. //----------------------------------------------------------------------------------------
  1689. // TCtlMgr::SetLongValues:
  1690. //----------------------------------------------------------------------------------------
  1691. #pragma segment MAControlRes
  1692.  
  1693. void TCtlMgr::SetLongValues(VCoordinate itsVal,
  1694.                             VCoordinate itsMin,
  1695.                             VCoordinate itsMax,
  1696.                             Boolean redraw)
  1697. {
  1698.     this->SetLongMax(itsMax, redraw);            // Must be first to get fBitsToShift setup
  1699.     this->SetLongMin(itsMin, redraw);
  1700.     this->SetLongVal(itsVal, redraw);
  1701. } // TCtlMgr::SetLongValues
  1702.  
  1703. //----------------------------------------------------------------------------------------
  1704. // TCtlMgr::GetHelpState:
  1705. //----------------------------------------------------------------------------------------
  1706. #pragma segment MAControlRes
  1707.  
  1708. short TCtlMgr::GetHelpState()
  1709. {
  1710.     short helpState;
  1711.     
  1712.     if (this->IsEnabled())
  1713.     {
  1714.         short ctlValue = this->GetVal();
  1715.         if (ctlValue == 1)
  1716.             helpState = kHMCheckedItem;
  1717.         else
  1718.             if (ctlValue > 1)
  1719.                 helpState = kHMOtherItem;
  1720.             else
  1721.                 helpState = kHMEnabledItem;
  1722.     }
  1723.     else
  1724.         helpState = kHMDisabledItem;
  1725.     
  1726.     return helpState;
  1727. }
  1728.  
  1729. //----------------------------------------------------------------------------------------
  1730. // TCtlMgr::UpdateCoordinates:
  1731. //----------------------------------------------------------------------------------------
  1732. #pragma segment MAControlRes
  1733.  
  1734. void TCtlMgr::UpdateCoordinates()// override 
  1735. {
  1736.     CPoint oldQDOrigin(fQDOrigin);
  1737.     VPoint oldViewToQDOffset(fViewToQDOffset);
  1738.  
  1739.     Inherited::UpdateCoordinates();
  1740.  
  1741.     if (fQDOrigin != oldQDOrigin || fViewToQDOffset != oldViewToQDOffset)
  1742.         this->AdjustCtlMgrControl(kDontRedraw);
  1743. } // TCtlMgr::UpdateCoordinates
  1744.  
  1745.  
  1746. //========================================================================================
  1747. // CLASS TScrollBar
  1748. //========================================================================================
  1749. #undef Inherited
  1750. #define Inherited TCtlMgr
  1751.  
  1752. #pragma segment MAOpen
  1753. MA_DEFINE_CLASS_M1(TScrollBar, Inherited);
  1754.  
  1755. //----------------------------------------------------------------------------------------
  1756. // TScrollBar constructor
  1757. //----------------------------------------------------------------------------------------
  1758. #pragma segment MAOpen
  1759.  
  1760. TScrollBar::TScrollBar()
  1761. {
  1762.     fDirection = hSel;
  1763.     fEventNumber = mHScrollBarHit;
  1764.     fHandlesFirstClicks = FALSE;
  1765. } // TScrollBar::TScrollBar
  1766.  
  1767. //----------------------------------------------------------------------------------------
  1768. // TScrollBar destructor
  1769. //----------------------------------------------------------------------------------------
  1770. #pragma segment MADestructorRes
  1771.  
  1772. TScrollBar::~TScrollBar()
  1773. {
  1774. }
  1775.  
  1776. //----------------------------------------------------------------------------------------
  1777. // TScrollBar::IScrollBar:
  1778. //----------------------------------------------------------------------------------------
  1779. #pragma segment MAOpen
  1780.  
  1781. void TScrollBar::IScrollBar(TView* itsSuperView,
  1782.                             const VPoint& itsLocation,
  1783.                             const VPoint& itsSize,
  1784.                             SizeDeterminer itsHSizeDet,
  1785.                             SizeDeterminer itsVSizeDet,
  1786.                             VHSelect itsDirection,
  1787.                             long itsVal,
  1788.                             long itsMin,
  1789.                             long itsMax)
  1790. {
  1791.     this->ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, gEmptyString, itsVal, itsMin, itsMax, scrollBarProc);
  1792.     fDirection = itsDirection;
  1793.  
  1794.     if (itsDirection == hSel)
  1795.         fEventNumber = mHScrollBarHit;
  1796.     else
  1797.         fEventNumber = mVScrollBarHit;
  1798. } // TScrollBar::IScrollBar
  1799.  
  1800. //----------------------------------------------------------------------------------------
  1801. // TScrollBar::GetStandardSignature:
  1802. //----------------------------------------------------------------------------------------
  1803. #pragma segment MAWriteResource
  1804.  
  1805. IDType TScrollBar::GetStandardSignature()    // override 
  1806. {
  1807.     return kStdScrollBar;
  1808. } // TScrollBar::GetStandardSignature
  1809.  
  1810. //----------------------------------------------------------------------------------------
  1811. // TScrollBar::ReadFields:
  1812. //----------------------------------------------------------------------------------------
  1813. #pragma segment MAReadResource
  1814.  
  1815. void TScrollBar::ReadFields(TStream* aStream)                // override 
  1816. {
  1817.     Inherited::ReadFields(aStream);
  1818.     
  1819.     FailInfo fi;
  1820.     Try(fi)
  1821.     {
  1822.         fDirection = (VHSelect) aStream->ReadByte();
  1823.     
  1824.         long initialValue = aStream->ReadLong();
  1825.         long minimumValue = aStream->ReadLong();
  1826.         long maximumValue = aStream->ReadLong();
  1827.     
  1828.         this->CreateCMgrControl(gEmptyString, initialValue, minimumValue, maximumValue, scrollBarProc);
  1829.         fi.Success();
  1830.     }
  1831.     else
  1832.     {
  1833.         this->Free();
  1834.         fi.ReSignal();
  1835.     }
  1836. } // TScrollBar::ReadFields
  1837.  
  1838. //----------------------------------------------------------------------------------------
  1839. // TScrollBar::WriteFields:
  1840. //----------------------------------------------------------------------------------------
  1841. #pragma segment MAWriteResource
  1842.  
  1843. void TScrollBar::WriteFields(TStream* aStream)        // override 
  1844. {
  1845.     Inherited::WriteFields(aStream);
  1846.  
  1847.     aStream->WriteByte(fDirection);
  1848.  
  1849.     aStream->WriteLong(fLongVal);
  1850.     aStream->WriteLong(fLongMin);
  1851.     aStream->WriteLong(fLongMax);
  1852. } // TScrollBar::WriteFields
  1853.  
  1854. //----------------------------------------------------------------------------------------
  1855. // TScrollBar::ActionProc:
  1856. //----------------------------------------------------------------------------------------
  1857. #pragma segment MAControlRes
  1858.  
  1859. void TScrollBar::ActionProc(short partCode)
  1860. {
  1861.     Boolean backwards;
  1862.  
  1863.     if (partCode != 0)
  1864.     {
  1865.         backwards = ((partCode == kControlUpButtonPart) || (partCode == kControlPageUpPart));
  1866.  
  1867.         if ((backwards && (fLongVal > fLongMin)) || ((!backwards) && (fLongVal < fLongMax)))
  1868.             this->TrackScrollBar(partCode);
  1869.  
  1870.         this->Update();                            // Make sure that we're in synch before
  1871.                                                 // returning
  1872.         this->Focus();                            // make sure i am looking at myself… e.e. cummings
  1873.     }
  1874. } // TScrollBar::ActionProc
  1875.  
  1876. //----------------------------------------------------------------------------------------
  1877. // TScrollBar::DeltaValue:
  1878. //----------------------------------------------------------------------------------------
  1879. #pragma segment MAScroll
  1880.  
  1881. void TScrollBar::DeltaValue(VCoordinate delta)
  1882. {
  1883.     if (delta != 0)                                // Ensure that delta does not cause an overflow (or underflow)
  1884.         this->SetLongVal(fLongVal + MinMax(fLongMin - fLongVal, delta, fLongMax - fLongVal), fShown);
  1885. } // TScrollBar::DeltaValue
  1886.  
  1887. //----------------------------------------------------------------------------------------
  1888. // TScrollBar::DoMouseCommand:
  1889. //----------------------------------------------------------------------------------------
  1890. #pragma segment MAScroll
  1891.  
  1892. void TScrollBar::DoMouseCommand(VPoint& theMouse,
  1893.                                 TToolboxEvent* /* event */,
  1894.                                 CPoint /* hysteresis */)        // override
  1895. {
  1896.     VCoordinate newLongValue;
  1897.  
  1898. #if qDebug
  1899.     this->AssumeFocused();
  1900. #endif
  1901.  
  1902.     CPoint theQDMouse = this->ViewToQDPt(theMouse);
  1903.     VCoordinate oldLongValue = fLongVal;
  1904.  
  1905.     CWhileFocused itsWhileFocused(this, kRedraw);
  1906.  
  1907.     switch (TestControl(fCMgrControl, theQDMouse))
  1908.     {
  1909.         case kControlUpButtonPart:
  1910.         case kControlDownButtonPart:
  1911.         case kControlPageUpPart:
  1912.         case kControlPageDownPart:
  1913.             // note: the braces defeat an xlC warning
  1914.             {
  1915.             ControlActionUPP actionProc = NewControlActionProc(&ActionProcForTScrollBar);
  1916.             FailNIL(actionProc);
  1917.             TrackControl(fCMgrControl, theQDMouse, actionProc);
  1918.             actionProc = (ControlActionUPP)DisposeIfRoutineDescriptor((UniversalProcPtr)actionProc);
  1919.             }
  1920.  
  1921.             // This method MUST inform its superview of the change! Thanks to GLB!
  1922.             if (fLongVal != oldLongValue)
  1923.                 this->HandleEvent(fEventNumber, this, NULL);
  1924.             break;
  1925.         case kControlIndicatorPart: // Thumb
  1926.             if (TrackControl(fCMgrControl, theQDMouse, NULL) == kControlIndicatorPart)
  1927.             {
  1928.                 // If thumb is dragged to bottom of scroll bar then ensure that the new
  1929.                 // long value is set to the maximum long value. We get killed by side
  1930.                 // effects if we don't use a temporary variable here. This doesn't show up
  1931.                 // in the TScrollerScrollBar class because this code is overridden, but it
  1932.                 // will show up in derived classes that depend on this code
  1933.                 if (this->GetVal() == this->GetMax())
  1934.                     newLongValue = fLongMax;
  1935.                 else
  1936.                     newLongValue = ((long)GetVal() << fBitsToShift);
  1937.  
  1938.                 this->SetLongVal(newLongValue, kRedraw);
  1939.  
  1940.                 // This method MUST inform its superview of the change! 
  1941.                 if (fLongVal != oldLongValue)
  1942.                     this->HandleEvent(fEventNumber, this, NULL);
  1943.             }
  1944.             break;
  1945.     }
  1946. } // TScrollBar::DoMouseCommand
  1947.  
  1948. //----------------------------------------------------------------------------------------
  1949. // TScrollBar::TrackScrollBar:
  1950. //----------------------------------------------------------------------------------------
  1951. #pragma segment MAControlRes
  1952.  
  1953. void TScrollBar::TrackScrollBar(short partCode)
  1954. {
  1955.     this->DeltaValue((partCode == kControlPageUpPart) || (partCode == kControlUpButtonPart) ? -1 : 1);
  1956. } // TScrollBar::TrackScrollBar
  1957.  
  1958.  
  1959. //========================================================================================
  1960. // CLASS TScrollerScrollBar
  1961. //========================================================================================
  1962. #undef Inherited
  1963. #define Inherited TScrollBar
  1964.  
  1965. #pragma segment MAOpen
  1966. MA_DEFINE_CLASS_M1(TScrollerScrollBar, Inherited);
  1967.  
  1968. //----------------------------------------------------------------------------------------
  1969. // TScrollerScrollBar constructor
  1970. //----------------------------------------------------------------------------------------
  1971. #pragma segment MAOpen
  1972.  
  1973. TScrollerScrollBar::TScrollerScrollBar()
  1974. {
  1975.     fScrollers = NULL;
  1976. } // TScrollerScrollBar::TScrollerScrollBar
  1977.  
  1978. //----------------------------------------------------------------------------------------
  1979. // TScrollerScrollBar::IScrollerScrollBar:
  1980. //----------------------------------------------------------------------------------------
  1981. #pragma segment MAOpen
  1982.  
  1983. void TScrollerScrollBar::IScrollerScrollBar(TView* itsSuperView,
  1984.                                             const VPoint& itsLocation,
  1985.                                             const VPoint& itsSize,
  1986.                                             SizeDeterminer itsHSizeDet,
  1987.                                             SizeDeterminer itsVSizeDet,
  1988.                                             VHSelect itsDirection,
  1989.                                             long itsMax,
  1990.                                             TScroller* itsScroller)
  1991. {
  1992.     this->IScrollBar(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsDirection, 0, 0, itsMax);
  1993.     this->SetCMgrVisibility(this->IsActive());
  1994.  
  1995.     FailInfo fi;
  1996.     Try(fi)
  1997.     {
  1998.         fScrollers = NewList();
  1999. #if qDebug
  2000.         fScrollers->SetEltType("TScroller");
  2001. #endif
  2002.  
  2003.         this->AttachScroller(itsScroller);
  2004.         fi.Success();
  2005.     }
  2006.     else                                        // Recover
  2007.         {
  2008.             this->Free();
  2009.             fi.ReSignal();
  2010.         }
  2011. } // TScrollerScrollBar::IScrollerScrollBar
  2012.  
  2013. //----------------------------------------------------------------------------------------
  2014. // TScrollerScrollBar::Clone:
  2015. //----------------------------------------------------------------------------------------
  2016. #pragma segment MAControlNonRes
  2017.  
  2018. TObject* TScrollerScrollBar::Clone()    // override 
  2019. {
  2020.     TScrollerScrollBar * aScrollerScrollBar = (TScrollerScrollBar *)(Inherited::Clone());
  2021.  
  2022. #if qDebug
  2023.     if (aScrollerScrollBar->fScrollers->GetSize() != 1)
  2024.         ProgramBreak("###TScrollerScrollBar.Clone: Unexpected number of scrollers!");
  2025. #endif
  2026.  
  2027.     aScrollerScrollBar->fScrollers = NewList();
  2028.  
  2029.     return aScrollerScrollBar;
  2030. } // TScrollerScrollBar::Clone
  2031.  
  2032. //----------------------------------------------------------------------------------------
  2033. // TScrollerScrollBar::Free:
  2034. //----------------------------------------------------------------------------------------
  2035. #pragma segment MAClose
  2036.  
  2037. TScrollerScrollBar::~TScrollerScrollBar()
  2038. {
  2039.     {
  2040.         CObjectIterator iter(fScrollers);
  2041.     
  2042.         for (TScroller * theScroller = (TScroller *)iter.FirstObject(); iter.More(); theScroller = (TScroller *)iter.NextObject())
  2043.             if (theScroller->fScrollBars[fDirection] == this)
  2044.                 theScroller->HaveScrollBar(NULL, fDirection);
  2045.     }
  2046.     
  2047.     fScrollers = (TList *)(FreeIfObject(fScrollers));
  2048. } // TScrollerScrollBar::Free
  2049.  
  2050. //----------------------------------------------------------------------------------------
  2051. // TScrollerScrollBar::GetStandardSignature:
  2052. //----------------------------------------------------------------------------------------
  2053. #pragma segment MAWriteResource
  2054.  
  2055. IDType TScrollerScrollBar::GetStandardSignature()    // override 
  2056. {
  2057.     return kStdScrollerScrollBar;
  2058. } // TScrollerScrollBar::GetStandardSignature
  2059.  
  2060. //----------------------------------------------------------------------------------------
  2061. // TScrollerScrollBar::ReadFields:
  2062. //----------------------------------------------------------------------------------------
  2063. #pragma segment MAReadResource
  2064.  
  2065. void TScrollerScrollBar::ReadFields(TStream* aStream)                // override 
  2066. {
  2067.     Inherited::ReadFields(aStream);
  2068.  
  2069.     this->SetCMgrVisibility(this->IsActive());
  2070.  
  2071.     FailInfo fi;
  2072.     Try(fi)
  2073.     {
  2074.         fScrollers = NewList();
  2075. #if qDebug
  2076.         fScrollers->SetEltType("TScroller");
  2077. #endif
  2078.         fi.Success();
  2079.     }
  2080.     else                                        // Recover
  2081.     {
  2082.         this->Free();
  2083.         fi.ReSignal();
  2084.     }
  2085. } // TScrollerScrollBar::ReadFields
  2086.  
  2087. //----------------------------------------------------------------------------------------
  2088. // TScrollerScrollBar::WriteFields:
  2089. //----------------------------------------------------------------------------------------
  2090. #pragma segment MAWriteResource
  2091.  
  2092. void TScrollerScrollBar::WriteFields(TStream* aStream)        // override 
  2093. {
  2094.     Inherited::WriteFields(aStream);
  2095.  
  2096. } // TScrollerScrollBar::WriteFields
  2097.  
  2098. //----------------------------------------------------------------------------------------
  2099. // TScrollerScrollBar::Activate:
  2100. //----------------------------------------------------------------------------------------
  2101. #pragma segment MAActivate
  2102.  
  2103. void TScrollerScrollBar::Activate(Boolean entering)// override
  2104. {
  2105.     CWhileFocused itsWhileFocused(this, kRedraw);
  2106.  
  2107.     this->SetCMgrVisibility(entering);
  2108.     this->DrawContents();
  2109. } // TScrollerScrollBar::Activate
  2110.  
  2111. //----------------------------------------------------------------------------------------
  2112. // TScrollerScrollBar::AttachScroller:
  2113. //----------------------------------------------------------------------------------------
  2114. #pragma segment MAOpen
  2115.  
  2116. void TScrollerScrollBar::AttachScroller(TScroller* itsScroller)
  2117. {
  2118.     if (itsScroller)
  2119.     {
  2120.         // create a fake fIdentifier for TScrollerScrollBar, if needed
  2121.         if (fIdentifier == kNoIdentifier)
  2122.         {
  2123.             IDType tempID = itsScroller->fIdentifier;
  2124.             Ptr hiBytePtr = (Ptr) &tempID;
  2125.  
  2126.             if (fDirection == vSel)
  2127.                 *hiBytePtr = 'v';
  2128.             else
  2129.                 *hiBytePtr = 'h';
  2130.             
  2131.             fIdentifier = tempID;
  2132.         }
  2133.     
  2134.         fScrollers->Insert(itsScroller);
  2135.         itsScroller->HaveScrollBar(this, fDirection);
  2136.     }
  2137. } // TScrollerScrollBar::AttachScroller
  2138.  
  2139. //----------------------------------------------------------------------------------------
  2140. // TScrollerScrollBar::BeInPort:
  2141. //----------------------------------------------------------------------------------------
  2142. #pragma segment MAControlNonRes
  2143.  
  2144. void TScrollerScrollBar::BeInPort(GrafPtr itsPort)// override
  2145. {
  2146.     Inherited::BeInPort(itsPort);
  2147.  
  2148.     this->SetCMgrVisibility(this->IsActive());
  2149. } // TScrollerScrollBar::BeInPort
  2150.  
  2151. //----------------------------------------------------------------------------------------
  2152. // TScrollerScrollBar::DoMouseCommand:
  2153. //----------------------------------------------------------------------------------------
  2154. #pragma segment MAScroll
  2155.  
  2156. void TScrollerScrollBar::DoMouseCommand(VPoint& theMouse,
  2157.                                         TToolboxEvent* event,
  2158.                                         CPoint hysteresis)    // override 
  2159. {
  2160.  
  2161. #if qDebug
  2162.     this->AssumeFocused();
  2163. #endif
  2164.  
  2165.     CPoint theQDMouse = this->ViewToQDPt(theMouse);
  2166.  
  2167.     CWhileFocused itsWhileFocused(this, kRedraw);
  2168.  
  2169.     if (TestControl(fCMgrControl, theQDMouse) == kControlIndicatorPart) // Thumb
  2170.     {
  2171.         if (TrackControl(fCMgrControl, theQDMouse, NULL) == kControlIndicatorPart)
  2172.         {
  2173.             // If thumb is dragged to bottom of scroll bar then ensure that
  2174.             // the new long value is set to the maximum long value.
  2175.             if (this->GetVal() == this->GetMax())
  2176.                 fLongVal = fLongMax;
  2177.             else
  2178.                 fLongVal = (this->GetVal() << fBitsToShift);
  2179.  
  2180.             long sBarDelta = 0;
  2181.             CObjectIterator iter(fScrollers);
  2182.         
  2183.             for (TScroller * theScroller = (TScroller *)iter.FirstObject(); iter.More(); theScroller = (TScroller *)iter.NextObject())
  2184.                 sBarDelta += theScroller->ScrollRelative(fDirection, fLongVal);
  2185.  
  2186.             if (this->Focus() && (sBarDelta != 0))
  2187.                 this->SetLongVal(fLongVal + sBarDelta, kRedraw);
  2188.         }
  2189.     }
  2190.     else
  2191.         Inherited::DoMouseCommand(theMouse, event, hysteresis);
  2192. } // TScrollerScrollBar::DoMouseCommand
  2193.  
  2194. //----------------------------------------------------------------------------------------
  2195. // TScrollerScrollBar::Draw:
  2196. //----------------------------------------------------------------------------------------
  2197. #pragma segment MAControlRes
  2198.  
  2199. void TScrollerScrollBar::Draw(const VRect& area)// override
  2200. {
  2201. #if qDebug
  2202.     this->AssumeFocused();
  2203. #endif
  2204.  
  2205.     if (!IsCMgrVisible())
  2206.     {
  2207.         CRGBColor savedBkColor;
  2208.         
  2209.         PenNormal();
  2210.         GetIfBkColor(savedBkColor);
  2211.         SetIfBkColor(gRGBWhite);
  2212.  
  2213.         CWhileFocused itsWhileFocused(this, kRedraw);
  2214.         CRect itsRect = (*fCMgrControl)->contrlRect;
  2215.  
  2216.         EraseRect(itsRect);
  2217.         FrameRect(itsRect);
  2218.         SetIfBkColor(savedBkColor);
  2219.     }
  2220.  
  2221.     Inherited::Draw(area);
  2222. } // TScrollerScrollBar::Draw
  2223.  
  2224. //----------------------------------------------------------------------------------------
  2225. // TScrollerScrollBar::TrackScrollBar:
  2226. //----------------------------------------------------------------------------------------
  2227. #pragma segment MAScroll
  2228.  
  2229. void TScrollerScrollBar::TrackScrollBar(short partCode)
  2230. {
  2231.     long sBarDelta = 0;
  2232.  
  2233.     CObjectIterator iter(fScrollers);
  2234.  
  2235.     for (TScroller * theScroller = (TScroller *)iter.FirstObject(); iter.More(); theScroller = (TScroller *)iter.NextObject())
  2236.         sBarDelta += theScroller->ScrollStep(fDirection, partCode);
  2237.  
  2238.     if (this->Focus())
  2239.         this->DeltaValue(sBarDelta);
  2240. } // TScrollerScrollBar::TrackScrollBar
  2241.  
  2242. //----------------------------------------------------------------------------------------
  2243. // End of UControl.cp
  2244.  
  2245. #pragma segment Inline
  2246.